import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;


public class SelectRangeForm extends Form implements CommandListener
{
	UnicodeCanvas canvas;


	ChoiceGroup rangeChoice;

	public SelectRangeForm(UnicodeCanvas canvas)
	{
		super("Select Range");

		this.canvas = canvas;

		rangeChoice = new ChoiceGroup("Range: ", Choice.EXCLUSIVE, canvas.rangeNames, null);
		rangeChoice.setSelectedIndex(canvas.currentRange, true);
		append(rangeChoice);

		addCommand(new Command("Go", Command.OK, 0));
		addCommand(new Command("Cancel", Command.CANCEL, 0));

		setCommandListener(this);
	}

	public void commandAction(Command command, Displayable d)
	{
		if (command.getCommandType() == Command.CANCEL)
		{
			Display.getDisplay(canvas.midlet).setCurrent(canvas);
		}
		else if (command.getCommandType() == Command.OK)
		{
			canvas.setSelectedCharacter(canvas.offsets[rangeChoice.getSelectedIndex()]);
			Display.getDisplay(canvas.midlet).setCurrent(canvas);
		}
	}


}
